$(document).ready(function(){
	
	getCurrent(1,10);
	
	$('#firstPage').click(function(){		
		var page=1;
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
	});
	
	$('#prePage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)-1);
		var maxRow=$("#maxRow").text();
		if(page<=0){
			alert("第一页了");
			return ;
		}
		getCurrent(page,maxRow);
	});
	
	$('#nextPage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		if(page>=pageCount){
			alert("最后一页了");
			return;
		}
		getCurrent(page,maxRow);
	});
	
	$('#lastPage').click(function(){		
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
		
	});
	
	$('#jumpPage').click(function(){		
		var pageCount=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var page=$("#jump").val();
		if(page>pageCount){
			alert("页数过大");
			return;
		}
		getCurrent(page,maxRow);
	});

	
	
});

	function getCurrent(page1,maxRow1){
		var page=page1;
		var maxRow=maxRow1;
		var typeID=$(window.parent.frames["topFrame"].document).find('#lawTypeID option:selected').val();
		var lawNatureID=$(window.parent.frames["topFrame"].document).find('#lawNatureID option:selected').val();
		var lawName=$(window.parent.frames["topFrame"].document).find('#top_lawNameID').val();
		var lawkey=$(window.parent.frames["topFrame"].document).find('#lawkeyID').val();
		$('#lawBody').empty();
		$("#loadingPerson").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeLaw_findLawList.action",
 			data:{
 				  typeID1:typeID,lawNature1:lawNatureID,lawName1:lawName,lawDetail1:lawkey,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		 });	
	}

	function getLawDetail(v){
		var content = $(v).next().text();
		window.location.href="/ag/hmk/findOneLaw_findOneLaw.action?lawID1="+content ;//+"&findType1=1";
	}
	
	//删除法规
	function delLaw(v){
		var isPass = confirm("确定要删除吗？");
		if(isPass){
			var lawID = $(v).next().text();
			var url = 'hmk/delLaw_delLaw.action';
			var params = {
				lawID1:lawID
			}; 
			jQuery.post(url, params, delData, 'json');
		}
		
	}

	function delData(data){
		if(data.delString=='1'){
			alert("删除成功");
			window.location.replace("/ag/hmk/LawMain.jsp");
		 }else{
			alert("删除失败");
		 }
	}

	
	
	function showData(data){
		$('#lawBody').empty();	
		if(data.pageUtil.list.length==0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			$("#maxRow").text(0);
		}else{
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
				fillDataToHtml(n.lawId,n.tbType.tpyeName,n.tbLawnature.lnName,
							   n.lawName,n.lawDetail,data.lawKeywordList[i],n.lawFjRote,n.lawFjName);
						  
		  	});
		
		$('#total').text(data.pageUtil.total);
		$('#page').text(data.pageUtil.page);
		$('#pageCount').text(Math.ceil(data.pageUtil.total/10));
		$('#maxRow').text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(lid,ltype,lnature,lname,ldetail,lkeyword,lfjname,lawFjName){
		var strHtml="<tr>";
		
		strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ltype+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lnature+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lname+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ldetail+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lkeyword+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=lfjname+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><img src='hmk/images/037.gif' width='9' height='9' /><span class='STYLE1'> [</span><a style='cursor:pointer' onclick='getLawDetail(this)'>详情</a>";
			strHtml+="<span id='cID' style='display:none'>";
	    	strHtml+=lid;
	    	strHtml+="</span>";        
        strHtml+="<span class='STYLE1'>]</span></div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><span class='STYLE2'><img src='hmk/images/010.gif' width='9' height='9' /> </span><span class='STYLE1'>[</span><a style='cursor:pointer' onclick='delLaw(this)'>删除</a>";
        	strHtml+="<span id='cID' style='display:none'>";
	    	strHtml+=lid;
	    	strHtml+="</span>";
        strHtml+="<span class='STYLE1'>]</span></div></td>"
        strHtml+="</tr>";
        
        $('#lawBody').append(strHtml);
        
	}
	
//	function downloadFile(obj){
//		
//	   var url= $(obj).next().text();
//		//alert(url);
//		var url_request="file/download!getDownloadFile.action";
//		var realName=$(obj).siblings(".lfjname").text();
//		
//		var url_data={moduleID:102,
//				fileRealName:realName,
//				       fileDiskURL:url};
//	   $.post(url_request,url_data,function(){});
//		
//	}